<template>
  <div class="jeecg-basic-table jeecg-basic-table-form-container">
    <!--引用表格-->
    <BasicTable @register="registerTable" :expandedRowKeys="expandedRowKeys" @expand="handleExpand">
      <!-- 内嵌table区域 begin -->
      <!-- <template #expandedRowRender="{ record }">
        <a-tabs tabPosition="top">
          <a-tab-pane tab="项目信息" key="labSample" forceRender>
            <LabItemsSubTable :id="expandedRowKeys[0]" :entrustId="record.entrustId" />
          </a-tab-pane>
        </a-tabs>
      </template> -->
      <!-- <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
      </template> -->
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <template #fileSlot="{ text }">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small"
          @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
    <!-- 领样表单区域 -->
    <LabSampleOutModal @register="registerOutModal" @success="handleSuccess"></LabSampleOutModal>
    <!-- 退回表单区域 -->
    <LabSampleModal @register="registerModal" @success="handleSuccess"></LabSampleModal>
    <!-- 条形码区域 -->
    <LabSampleBarModal @register="registeBarModal"> </LabSampleBarModal>
    <!-- 二维码弹窗 -->
    <LabSampleQrModal @register="registeQrModal"> </LabSampleQrModal>
    <!-- 样品处置 -->
    <LabSampleHandleModal @register="registerHModal" @success="handleSuccess"></LabSampleHandleModal>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
// import {useModal} from '/@/components/Modal';
import LabSampleOutModal from './components/LabSampleOutModal.vue'
import LabSampleModal from './components/LabSampleModal.vue'
import LabItemsSubTable from './subTables/LabItemsSubTable.vue'
import LabSampleQrModal from '/@/views/lab/wentrust/subTables/LabSampleQr.vue';
import { columns, searchFormSchema } from './LabSample.data';
import { entrutSampleList } from './LabSample.api';
// import { downloadFile } from '/@/utils/common/renderUtils';
import LabSampleBarModal from './LabSampleBar.vue';
import LabSampleHandleModal from '../sample_handle/components/LabSampleHandleForm.vue';


// 展开key
const expandedRowKeys = ref<any[]>([]);
const [registerOutModal, { openModal: oOpenModal }] = useModal();
const [registerModal, { openModal: sOpenModal }] = useModal();
//弹窗注册
const [registeBarModal, { openModal: bOpenModal }] = useModal();
//注册二维码弹窗
const [registeQrModal, { openModal: openModalQr }] = useModal();
//弹窗注册
const [registerHModal, { openModal: hOpenModal }] = useModal();

//注册table数据
const { tableContext, onExportXls } = useListPage({
  tableProps: {
    api: entrutSampleList,
    columns,
    canResize: false,
    showIndexColumn: true,
    showTableSetting: false,
    formConfig: {
      schemas: searchFormSchema,
      autoSubmitOnEnter: true,
      showAdvancedButton: true,
      fieldMapToNumber: [
      ],
      fieldMapToTime: [
      ],
    },
    actionColumn: {
      width: 120,
      fixed: 'right'
    },
  },
  // exportConfig: {
  //   name: "委托信息表",
  //   url: getExportUrl,
  // },
  // importConfig: {
  //   url: getImportUrl,
  //   success: handleSuccess
  // },
})


const [registerTable, { reload }, { selectedRowKeys }] = tableContext
/**
  * 展开事件
  * */
function handleExpand(expanded, record) {
  expandedRowKeys.value = [];
  if (expanded === true) {
    expandedRowKeys.value.push(record.id)
  }
}

//打开条形码弹窗
function openBarCode(record) {
  bOpenModal(true, record);//record 将数据传到条形模块中
}
// 打开二维码弹窗
function openQrCode(record) {
  openModalQr(true, record);//record 将数据传到条形模块中
}

/**
 * 领样
 */
 function sampleOut(record: Recordable) {
  oOpenModal(true, {
    record
  });
}


/**
 * 退回
 */
function sampleBack(record: Recordable) {
  sOpenModal(true, {
    record
  });
}

/**
 * 成功回调
 */
function handleSuccess() {
  (selectedRowKeys.value = []) && reload();
}

/**
 * 打开样品处置
 */
function handleOpen() {
  hOpenModal(true, {
    isUpdate: false,
    disabled: false,
    showFooter: true,
  });
}

/**
   * 操作栏
   */
function getTableAction(record) {
  if (record.samStatus == '备样') {
    // return [
    //   {
    //     label: '条形码',
    //     onClick: openBarCode.bind(null, record),
    //   },
    //   {
    //     label: '二维码',
    //     onClick: openQrCode.bind(null, record),
    //   }
    // ]
  } else {
    return [
    {
        label: '出库',
        onClick: sampleOut.bind(null, record),
        disabled:record.samStatus !='待检'
      },
      {
        label: '回收',
        onClick: sampleBack.bind(null, record),
        disabled:record.samStatus !='在检'
      },
      // {
      //   label: '条形码',
      //   onClick: openBarCode.bind(null, record),
      // },
      // {
      //   label: '二维码',
      //   onClick: openQrCode.bind(null, record),
      // }
    ]
  }
}



</script>

<style lang="less" scoped>

:deep(.ant-table-title) {
    display: none;
  }
</style>
